<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2019/4/26
 * Time: 11:00
 */
namespace Modules\Admin\Main\Controllers;

use App\Http\Controllers\Controller;
use App\Models\OilCard;
use App\Models\ShopOrder;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;

class OilCardPullController extends Controller
{
    public function search()
    {
        return view('main::oil_card_pull', \Request::all());
    }

    public function apiSearch(Request $request)
    {
        $limit = $request->input('limit', 10); // 这个是接受参数
        $offset = $request->input('offset', 0);
        $order_status = $request->input('order_status',1);
        $data = [];

        $query = ShopOrder::query();

        $data['total'] = $query->where("order_type","oil_card")->where("order_status",$order_status)->count();
        $data['items'] = $query->where("order_type","oil_card")->where("order_status",$order_status)->with('detail')->take($limit)
            ->skip($offset)
            ->orderBy('id', 'desc')
            ->get();

        return success($data);
    }

    public function update(Request $request,$id){
        $shippingCode = $request->input("shipping_code");
        $shippingCompany = $request->input("shipping_company");
        $order = ShopOrder::find($id);
        $order->shipping_code = $shippingCode;
        $order->shipping_company = $shippingCompany;
        $order->send_time = Carbon::now();
        $order->order_status = 2;
        $order->save();
        return success();
    }
}